﻿using Basmus.ReadWrite;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Basmus.Tests.ReadWrite
{
    [TestClass()]
    public class ReadResultTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod()]
        public void EqualsTest()
        {
            var readResult = ReadResult.Success(100, typeof(int));

            var targetReadResult = ReadResult.Success(100, typeof(int));

            Assert.IsTrue(targetReadResult.Equals(readResult));
            Assert.AreEqual(readResult.GetHashCode(), targetReadResult.GetHashCode());
        }

        [TestMethod()]
        public void NotEqualsForNullTest()
        {
            var targetReadResult = ReadResult.Success(100, typeof(int));

            Assert.IsFalse(targetReadResult.Equals(null));
        }

        [TestMethod()]
        public void NotEqualsForSuccessfulTest()
        {
            var readResult = ReadResult.Success(100, typeof(int));
            var targetReadResult = ReadResult.Error(100, typeof (int));

            Assert.IsFalse(targetReadResult.Equals(readResult));
            Assert.AreNotEqual(readResult.GetHashCode(), targetReadResult.GetHashCode());
        }

        [TestMethod()]
        public void NotEqualsForTypeTest()
        {
            var readResult = ReadResult.Success(100, typeof(int));
            var targetReadResult = ReadResult.Success("", typeof (string));

            Assert.IsFalse(targetReadResult.Equals(readResult));
            Assert.AreNotEqual(readResult.GetHashCode(), targetReadResult.GetHashCode());
        }

        [TestMethod()]
        public void EqualsForResultNullTest()
        {
            var readResult = ReadResult.Success(null, typeof(int));
            var targetReadResult = ReadResult.Success(null, typeof (int));

            Assert.IsTrue(targetReadResult.Equals(readResult));
            Assert.AreEqual(readResult.GetHashCode(), targetReadResult.GetHashCode());
        }

        [TestMethod()]
        public void NotEqualsForResultNullTest()
        {
            var nullResult = ReadResult.Success(null, typeof (string));
            var notNullResult = ReadResult.Success("", typeof (string));

            Assert.IsFalse(nullResult.Equals(notNullResult));
            Assert.IsFalse(notNullResult.Equals(nullResult));
            Assert.AreNotEqual(nullResult.GetHashCode(), notNullResult.GetHashCode());
        }

        [TestMethod()]
        public void SuccessTest()
        {
            var result = new object();
            var resultType = typeof (object);

            var readResult = ReadResult.Success(result, resultType);


            Assert.IsTrue(readResult.Successful);
            Assert.AreEqual(readResult.Result, result);
            Assert.AreEqual(readResult.ResultType, resultType);
            
        }

        [TestMethod()]
        public void ErrorTest()
        {
            var result = new object();
            var resultType = typeof(object);

            var readResult = ReadResult.Error(result, resultType);


            Assert.IsFalse(readResult.Successful);
            Assert.AreEqual(readResult.Result, result);
            Assert.AreEqual(readResult.ResultType, resultType);
        }
    }
}
